package com.test;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.ibatis.datasource.DataSourceFactory;

public class MyDruid implements DataSourceFactory {

	private DataSource dataSource;

    @SuppressWarnings("rawtypes")
    public void initialize(Map map) {
        try {
            dataSource = com.alibaba.druid.pool.DruidDataSourceFactory.createDataSource(map);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException("init data source error", e);
        }
    }

    public DataSource getDataSource() {
        return dataSource;
    }

	public void setProperties(Properties props) {
		Map<Object, Object> map = new HashMap<Object, Object>();
		props.forEach((k, v) -> {
			map.put(k, v);
		});
		initialize(map);
	}

}
